package com.iemes.controller.process;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.ClientinfoMap;
import com.iemes.entity.MouldFormMap;
import com.iemes.mapper.MouldMapper;
import com.iemes.util.Common;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/mould/")
public class MouldController extends BaseController {
    @Inject
    private MouldMapper mouldMapper;

    @RequestMapping("mouldIndex")
    public String index(Model model){
        String[] btnArray = new String[]{"<button type=\"button\" id=\"addAccount\" class=\"btn btn-primary marR10\">新增</button>", "<button type=\"button\" id=\"editAccount\" class=\"btn btn-info marR10\">编辑</button>", "<button type=\"button\" id=\"delAccount\" class=\"btn btn-danger marR10\">删除</button>"};
        model.addAttribute("res", findByRes());
        model.addAttribute("btn", btnArray);
        return Common.BACKGROUND_PATH + "/process/mould/mouldIdex";
    }

    //获取数据进行分页
    @ResponseBody
    @RequestMapping("getMouldPage")
    public PageInfo getDataPage(){
        PageHelper.startPage(1, 10);
        List<MouldFormMap> orderFormMapList = mouldMapper.selMouldPage();
        PageInfo pageInfo = new PageInfo<>(orderFormMapList);
        return pageInfo;
    }
    @ResponseBody
    @RequestMapping("addMould")
//    @SystemLog(module="系统管理",methods="客户管理-新增客户")//凡需要处理业务逻辑的.都需要记录操作日志
    @Transactional(readOnly=false)//需要事务操作必须加入此注解
    public String addUserManagement(){
        //获取数据

        MouldFormMap clientinfoMap = getFormMap(MouldFormMap.class);
        try {
            mouldMapper.addEntity(clientinfoMap);//新增后返回新增信息
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }
    @RequestMapping("openMouldManagementUI")
    public String openMouldManagementUI(){
        return Common.BACKGROUND_PATH + "/process/mould/addMoudel";
    }

    @RequestMapping("editMouldManagementUI")
    public String editMouldManagementUI(Model model, HttpServletRequest request){
        String id = getPara("id");
//        if(Common.isNotEmpty(id)){
//            model.addAttribute("user", userMapper.findbyFrist("clientId", id, ClientinfoMap.class));
//        }
        return Common.BACKGROUND_PATH + "/process/mould/editMoudel";
    }
}
